home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sun4c / archive / tcltk.z / tcltk / slib / tk / demos / browse next >
Text File  |  1994-09-20  |  2KB  |  54 lines

  1. #!///////////////////////////////////////////////////////////////////////////usr/STAGE/bin/wish -f
  2. #
  3. # This script generates a directory browser, which lists the working
  4. # directory and allows you to open files or subdirectories by
  5. # double-clicking.
  6.  
  7. # Create a scrollbar on the right side of the main window and a listbox
  8. # on the left side.
  9.  
  10. scrollbar .scroll -command ".list yview"
  11. pack .scroll -side right -fill y
  12. listbox .list -yscroll ".scroll set" -relief raised -geometry 20x20 \
  13.     -setgrid yes
  14. pack .list -side left -fill both -expand yes
  15. wm minsize . 1 1
  16.  
  17. # The procedure below is invoked to open a browser on a given file;  if the
  18. # file is a directory then another instance of this program is invoked; if
  19. # the file is a regular file then the Mx editor is invoked to display
  20. # the file.
  21.  
  22. proc browse {dir file} {
  23.     global env
  24.     if {[string compare $dir "."] != 0} {set file $dir/$file}
  25.     if [file isdirectory $file] {
  26.     exec browse $file &
  27.     } else {
  28.     if [file isfile $file] {
  29.         if [info exists env(EDITOR)] {
  30.         eval exec $env(EDITOR) $file &
  31.         } else {
  32.         exec xedit $file &
  33.         }
  34.     } else {
  35.         puts stdout "\"$file\" isn't a directory or regular file"
  36.     }
  37.     }
  38. }
  39.  
  40. # Fill the listbox with a list of all the files in the directory (run
  41. # the "ls" command to get that information).
  42.  
  43. if $argc>0 {set dir [lindex $argv 0]} else {set dir "."}
  44. foreach i [exec ls -a $dir] {
  45.     .list insert end $i
  46. }
  47.  
  48. # Set up bindings for the browser.
  49.  
  50. bind .list <Control-q> {destroy .}
  51. bind .list <Control-c> {destroy .}
  52. focus .list
  53. bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i}}
  54.